package com.hashimoto.user.test.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.hashimoto.core.remote.client.ClientConfig;
import com.hashimoto.core.remote.client.ClientType;
import com.hashimoto.core.remote.client.user.NettyUserClient;
import com.hashimoto.core.remote.client.user.UserCallBack;
import com.hashimoto.core.remote.client.user.UserClient;
import com.hashimoto.core.remote.exchange.CallBackMessage;
import com.hashimoto.core.remote.exchange.EventMessage;

@Configuration
public class BeanConfiguration {
	
	@Bean
	public UserClient userClient() {
		UserClient userClient = new NettyUserClient();
		ClientConfig config = new ClientConfig();
		config.setClientId(22222222);
		config.setConnectTimeout(300000);
		config.setPassword("123446");
		config.setUserType(ClientType.USERS);
		config.setUsrname("2222222");
		config.setRemoteHost("127.0.0.1");
		config.setRemotePort(9999);
		userClient.clientConfig(config);
		userClient.setUserCallBack(new UserCallBack() {   //数据回调
			
			@Override
			public void onMessage(CallBackMessage message) { //接口调用返回信息
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onEvent(EventMessage message) {   //接收订阅消息
				System.out.println(message.fromString());
				
			}
		});
		
		userClient.start();
		return userClient;
	}
	
//	public static void main(String[] args) {
//		Map<String,String> param = new HashMap<String,String>();
//		param.put("id", 1+"");
//		//SignalFuture future = userClient.callMessage("queryQrCode", 124563, param);
//		new BeanConfiguration().userClient().callMessage(null, 124563, param).get();
//	}

}
